let Vue;


class CVuex {
    $options;
    $state;
    $mutations;
    $actions;

    constructor(options) {
        this.$options = options
        Vue.util.defineReactive(this, "$state", options.state);
        this.$mutations = options.mutations;
        this.$actions = options.actions;

        this.commit = this.commit.bind(this)
        this.dispatch = this.dispatch.bind(this)
    }

    commit(name, payload) {
        const entry = this.$mutations[name] || null;
        if (entry) {
            entry(this.$state, payload)
            console.log(this.$state)
        }
    }

    dispatch(name, payload) {
        const entry = this.$actions[name] || null;
        if (entry) {
            entry(this, payload)
        }
    }
}

CVuex.install = function (_Vue) {
    Vue = _Vue;
    Vue.mixin({
        beforeCreate() {
            console.log(this.$options)
            if (this.$options.store) {//this.$options获取Vue实力化传入的属性！
                Vue.prototype.$store = this.$options.store
                console.log(Vue.prototype.$store)
            }
        }
    })
}
export default CVuex
